local hx__congyi = fk.CreateSkill{
  name = "hx__congyi",
  tags = { Skill.Limited },
}

hx__congyi:addEffect(fk.TargetSpecifying, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__congyi.name) and
      data.card.trueName == "slash" and data:isOnlyTarget(data.to) and
      player:usedSkillTimes(hx__congyi.name,Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local cards = to:getCardIds({Player.Hand,Player.Equip,Player.Judge})
    if #cards == 0 then return false end
    room:obtainCard(player, cards ,false, fk.ReasonPrey, player, hx__congyi.name)
    local x = #player:getCardIds({Player.Hand}) // 2
    local givecard = room:askToCards(player,{
      max_num = x,
      min_num = x,
      skill_name = hx__congyi.name,
      cancelable = false,
      include_equip = true,
      prompt = "请选择"..x.."张牌交给"..Fk:translate(to.general).."",
    })
    if #givecard == 0 then return false end
    room:obtainCard(to, givecard, true, fk.ReasonGive, player, hx__congyi.name)
    local p = player:getHandcardNum()
    local t = to:getHandcardNum()
    if p == t then
      local newto = table.filter(room:getAlivePlayers(),function(pl)
        return pl ~= to and pl ~= data.from
      end)
      if #newto > 0 then
        local new = room:askToChoosePlayers(to,{
          targets = newto,
          min_num = 1,
          max_num = 1,
          cancelable = true,
          skill_name = hx__congyi.name,
          prompt = "你可以将此【杀】目标改为除你和使用者以外的另一名角色",
        })
        if #new == 0 then return false end
        data:cancelTarget(to)
        data:addTarget(new[1])
      end
    end
  end,
})


return hx__congyi
